#include "StdAfx.h"
#include "xkRefAidPoint.h"

xkRefAidPoint::xkRefAidPoint(void)
{
	m_pImgBit = NULL;

	Initialize();
}

xkRefAidPoint::~xkRefAidPoint(void)
{
	UnInitialize();
}

int xkRefAidPoint::UnInitialize()
{
	m_pImgBit = NULL;

	return DD_ERR_SUCCESS;
}


int xkRefAidPoint::Initialize()
{
	m_xImgBit16.SetImgBit(&m_ImgBitInfo);
	m_xImgBit8.SetImgBit(&m_ImgBitInfo);

	return DD_ERR_SUCCESS;
}

int xkRefAidPoint::SetImgBuffer(zkImgBitInfo *pImgInfo,BOOL bShareMem)
{
	int nRet = DD_ERR_FAILURE;
	if( NULL == pImgInfo )
	{
		return nRet;
	}

	m_pImgBit = NULL;
	switch( pImgInfo->nImgDefine ) 
	{
	case eImage_Define_Img8:
		{
			m_pImgBit  = &m_xImgBit8;
		}
		break;
	case eImage_Define_Img16:
		{
			m_pImgBit  = &m_xImgBit16;
		}
		break;
	case eImage_Define_Img32:
		{
		}
		break;
	default:
		break;
	}

	do 
	{
		if( NULL == m_pImgBit )
		{
			break;
		}
		nRet = m_pImgBit->SetImgBuffer(pImgInfo,bShareMem);
		if( DD_ERR_SUCCESS != nRet )
		{
			break;;
		}

	} while (false);

	return nRet;
}

int xkRefAidPoint::GetImageSize(int &nWidth,int &nHeight)
{
	int nRet = DD_ERR_FAILURE;
	if( NULL == m_pImgBit )
	{
		return nRet;
	}

	return m_pImgBit->GetImageSize( nWidth,nHeight );
}

int xkRefAidPoint::GetImgBuffer(zkImgBitInfo **ppImgInfo)
{
	return m_pImgBit->GetImgBuffer( ppImgInfo );
}

int xkRefAidPoint::GetOrgImgBuffer(zkImgBitInfo **ppImgInfo)
{
	return m_pImgBit->GetOrgImgBuffer( ppImgInfo );
}





int xkRefAidPoint::LoadFile(char *pFileName)
{
	int nRet = -1;

	m_ImgBitInfo.nImgDefine  = eImage_Define_Img16;
	m_ImgBitInfo.bAutoDelete = FALSE;

	do 
	{
		m_pImgBit  = &m_xImgBit16;
		nRet = m_pImgBit->LoadFile(pFileName);
		if( DD_ERR_SUCCESS != nRet )
		{
			break;
		}

// 		nRet = GetRefDataFromFile(pFileName); 
// 		if( DD_ERR_SUCCESS != nRet )
// 		{
// 			break;
// 		}

		nRet = m_pImgBit->CreateKeyPoint();
		if( DD_ERR_SUCCESS != nRet )
		{
			break;
		}

	} while (false);

	return nRet;
}

int xkRefAidPoint::SaveFile(char *pFileName)
{
	int nRet = -1;

	do 
	{
		if( NULL == m_pImgBit )
		{
			break;
		}
		nRet = m_pImgBit->SaveFile( pFileName );
		if( DD_ERR_SUCCESS != nRet )
		{
			break;
		}
// 		nRet = SaveRefDataToFile( pFileName );
// 		if( DD_ERR_SUCCESS != nRet )
// 		{
// 			break;
// 		}

	} while (false);

	return nRet;
}




int xkRefAidPoint::CheckAidBuffer()
{
	return 0;
}

int xkRefAidPoint::CreateHostRelation(xfImgBit *pHostImgBit)
{
	return 0;
}